package com.test;

import java.io.*;
import java.util.ArrayList;

public class BufferedStreamTest2 {
    public static void main(String[] args) throws IOException {
        writerObject();
        BufferedReader br=new BufferedReader(new FileReader("D:\\stu.txt"));
        String line;
        ArrayList<Student> list=new ArrayList<>();
        while ((line= br.readLine())!=null){
            String[] arr=line.split("-");
            Student stu=new Student(arr[0],Integer.parseInt(arr[1]));
            list.add(stu);
        }
        for (Student student : list) {
            System.out.println(student);
        }



    }

    private static void writerObject() throws IOException {
        Student stu1=new Student("张三",23);
        Student stu2=new Student("李四",24);
        Student stu3=new Student("王五",25);
        BufferedWriter bf=new BufferedWriter(new FileWriter("D:\\stu.txt"));
        bf.write(stu1.getName()+"-"+stu1.getAge());
        bf.newLine();
        bf.write(stu2.getName()+"-"+stu2.getAge());
        bf.newLine();
        bf.write(stu3.getName()+"-"+stu3.getAge());
        bf.newLine();
        bf.close();
    }
}
